import Vue from 'vue'
import VueRouter from 'vue-router'
import AllQuesion from '../components/AllQuesion.vue'
import Home from '../components/Home.vue'
import Login from '../components/Login.vue'
import Section1_1 from '../components/Section1_1.vue'
import Section1_2 from '../components/Section1_2.vue'
import Section1_3 from '../components/Section1_3.vue'
import Section1_4 from '../components/Section1_4.vue'
import Section1_5 from '../components/Section1_5.vue'
import Section1_6 from '../components/Section1_6.vue'
import SectionOne from '../components/SectionOne.vue'
import SectionTwo from '../components/SectionTwo.vue'
import SectionThree from '../components/SectionThree.vue'
import SectionFour from '../components/SectionFour.vue'
import SectionFive from '../components/SectionFive.vue'
import SectionSix from '../components/SectionSix.vue'
import SectionSeven from '../components/SectionSeven.vue'



Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/Login' },
  { path: '/Login', component: Login },
  {
    path: '/Home',
    component: Home,
    redirect: '/Section1_1',
    children: [
      { path: '/Section1_1', component: Section1_1 },
      { path: '/Section1_2', component: Section1_2 },
      { path: '/Section1_3', component: Section1_3 },
      { path: '/Section1_4', component: Section1_4 },
      { path: '/Section1_5', component: Section1_5 },
      { path: '/Section1_6', component: Section1_6 },
      { path: '/SectionOne', component: SectionOne },
      { path: '/SectionTwo', component: SectionTwo },
      { path: '/SectionThree', component: SectionThree },
      { path: '/SectionFour', component: SectionFour },
      { path: '/SectionFive', component: SectionFive },
      { path: '/SectionSix', component: SectionSix },
      { path: '/SectionSeven', component: SectionSeven },
      { path: '/AllQuesion', component: AllQuesion },

    ]
  }

]

const router = new VueRouter({
  routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    next();
  } else if (window.sessionStorage.getItem("token")) {
    next();
  } else {
    next('/login')
  }
})

export default router
